﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ChequeManagement.BLL
{
    /// <summary>
    /// This Class Includes Field, constructor, Method that Inheritance of "BaseFactory" Class
    /// </summary>
    /// <Method>this class includes some method for add,edit,getall,remove data</Method>
    public class BLLDrawerFactory : BaseFactory
    {
        private ChequeManagement.DAL.DALDrawer dataObject = null;

        /// <summary>
        /// This constructor called base constructor and set parameter that parameter value is "Drawer"
        /// and use on create instance of class
        /// </summary>
        /// <base constructor>base constructor name is "BaseFactory" that get tableName and set tableName with this tableName</base constructor> 
        public BLLDrawerFactory()
            : base("Drawer")
        {
            dataObject = (ChequeManagement.DAL.DALDrawer)(base.DataAccessLayer);
        }

        /// <summary>
        /// This method get a object that type is ChequeManagement.BLL.BLLDrawer and check this object is valid or not valid if object is not valid throw a exception
        /// else if object is valid create a instance of ChequeManagement.DAL.DALDrawer class and call Insert method and set parameter
        /// </summary>
        /// <param name="drawerObject" Type="ChequeManagement.BLL.BLLDrawer"></param>
        /// <return>this type is void and Do not return</return>
        public void Add(ChequeManagement.BLL.BLLDrawer drawerObject)
        {
           
            {
                if (drawerObject.IsValid() == false)
                    throw (new ChequeManagement.Validation.InvalidBusinessObjectException(drawerObject.Errors));
                dataObject.Insert(drawerObject);
            }
            //catch (Exception ex)
            //{
            //    throw (ex);
            //}
        }

        /// <summary>
        /// This method get a object that type is ChequeManagement.BLL.BLLDrawer and a object that type is int
        /// this method create a instance of  ChequeManagement.BLL.BLLDrawer that name is "drawer" and set targetdrawerID on GetByKey method
        /// if drawerObject parameter is IsValid this method call dataObject that type is ChequeManagement.DAL.DALDrawer and call Update method and set parameter 
        /// else if drawerObject parameter not is IsValid throw exception
        /// </summary>
        /// <param name="drawerObject" Type="ChequeManagement.BLL.BLLDrawer"></param>
        /// <param name="targetdrawerID" Type="int"></param>
        /// <GetByKey method>this method declare on this page and call FetchByKey method on DAL layer and set parameter</GetByKey method>
        /// <return>this type is void and Do not return</return>
        public void Edit(ChequeManagement.BLL.BLLDrawer drawerObject, int targetdrawerID)
        {
            try
            {
                ChequeManagement.BLL.BLLDrawer drawer = this.GetByKey(targetdrawerID);

                if ((drawer != null) && (drawer.DrawerName.ToLower() == drawerObject.DrawerName.ToLower()))
                {
                    if (drawerObject.IsValid("DrawerName") == false)
                        throw (new ChequeManagement.Validation.InvalidBusinessObjectException(drawerObject.Errors));
                }
                else
                {
                    if (drawerObject.IsValid() == false)
                        throw (new ChequeManagement.Validation.InvalidBusinessObjectException(drawerObject.Errors));
                }
                dataObject.Update(drawerObject, targetdrawerID);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have a parameter that type is DataTable
        /// and call dataObject that type is ChequeManagement.DAL.DALDrawer and call FetchAll method and set parameter for select all data 
        /// </summary>
        /// <param name="dataTable" Type="DataTable"></param>
        /// <return>this type is void and Do not return but parameter is DataTable and result return into this DataTable</return>
        public void GetAll(DataTable dataTable)
        {
            try
            {
                dataObject.FetchAll(dataTable);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method not have parameter
        /// and call dataObject that type is ChequeManagement.DAL.DALDrawer and call FetchAll method for select all data
        /// </summary>
        /// <returns>List<></returns>
        public List<BLL.BLLDrawer> GetAll()
        {
            try
            {
                return (dataObject.FetchAll());
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameters
        /// and call dataObject that type is ChequeManagement.DAL.DALDrawer and call FetchByField method and set parameters
        /// the filedname parameter select field name on select table and vlaue parameter select value that select field name and result return into dataTable parameter 
        /// </summary>
        /// <param name="fieldName" Type="ChequeManagement.BLL.BLLDrawer.DrawerField"></param>
        /// <param name="value" Type="object"></param>
        /// <param name="dataTable" Type="DataTable"></param>
        /// <return>this type is void and Do not return but parameter is DataTable and result return into this DataTable</return>
        public void GetByField(ChequeManagement.BLL.BLLDrawer.DrawerField fieldName, object value,DataTable dataTable)
        {
            try
            { 
                dataObject.FetchByField(fieldName.ToString(), value,dataTable);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameter
        /// and call dataObject that type is ChequeManagement.DAL.DALDrawer and call FetchByField method and set parameters
        /// the filedname parameter select field name on select table and vlaue parameter select value that select field name
        /// </summary>
        /// <param name="fieldName" Type="ChequeManagement.BLL.BLLDrawer.DrawerField"></param>
        /// <param name="value" Type="object"></param>
        /// <returns>this method select data and result return into List<> that type is BLL.BLLDrawer</returns>
        public List<BLL.BLLDrawer> GetByField(ChequeManagement.BLL.BLLDrawer.DrawerField fieldName, object value)
        {
            try
            {
                return (dataObject.FetchByField(fieldName.ToString(), value));
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameter
        /// and call dataObject that type is ChequeManagement.DAL.DALDrawer and call FetchAllByCondition method and set parameters
        /// select data by this condition
        /// </summary>
        /// <param name="condition" Type="string"></param>
        /// <param name="dataTable" Type="DataTable"></param>
        /// <return>this type is void and Do not return but parameter is DataTable and result return into this DataTable</return>
        public void GetAllByCondition(string condition, DataTable dataTable)
        {
            try
            {
                dataObject.FetchAllByCondition(condition,dataTable);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameter
        /// and call dataObject that type is ChequeManagement.DAL.DALDrawer and call FetchByKey method and set parameters
        /// select data by targetBankID
        /// </summary>
        /// <param name="targetBankID" Type="int"></param>
        /// <returns>object that type is BLL.BLLDrawer</returns>
        public BLL.BLLDrawer GetByKey(int targetBankID)
        {
            try
            {
                return (dataObject.FetchByKey(targetBankID));
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameter
        /// and call dataObject that type is ChequeManagement.DAL.DALDrawer and call Delete method and set parameters
        /// </summary>
        /// <param name="targetBankID" Type="int"></param>
        /// <return>this type is void and Do not return</return>
        public void Remove(int targetBankID)
        {
            try
            {
                dataObject.Delete(targetBankID);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// This method have parameter
        /// and call dataObject that type is ChequeManagement.DAL.DALDrawer and call Delete method and set parameters
        /// remove field from table by this fieldName that value is this value
        /// </summary>
        /// <param name="fieldName" Type="ChequeManagement.BLL.BLLDrawer.DrawerField"></param>
        /// <param name="value" Type="object"></param>
        /// <return>this type is void and Do not return</return>
        public void Remove(ChequeManagement.BLL.BLLDrawer.DrawerField fieldName, object value)
        {
            try
            {
                dataObject.Delete(fieldName.ToString(), value);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
      
    }
}
